<template>
  <div id="login">
    <div class="loginBox">
      <div class="left">
        <img src="../../images/ic_zuo.png" alt="" />
      </div>
      <div class="right">
        <div class="rightBody">
          <div class="tit">
            <p>后台管理系统</p>
          </div>
          <label class="label">
            <img src="../../images/ic_zh.png" alt="" />
            <a-input
              class="input"
              v-model:value="usernameValue"
              placeholder="请输入账号"
            />
          </label>
          <label class="label">
            <img src="../../images/ic_mm.png" alt="" />
            <a-input-password
              class="input"
              v-model:value="passwordValue"
              placeholder="请输入密码"
            />
          </label>
          <a-button class="button" type="primary" block @click="loginButton"
            >登录</a-button
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from "vue";
import { message } from "ant-design-vue";
import router from "@/router";
import $store from "@/store";
import { Myrequest } from "@/network/request";
export default defineComponent({
  name: "login",
  setup() {
    const usernameValue = ref("");
    const passwordValue = ref("");
    const loginButton = () => {
      if (!usernameValue.value || !passwordValue.value) {
        message.error("账户与密码不能为空");
        return false;
      } else {
        Myrequest("post", "/admin/v1/login", {
          username: usernameValue.value,
          password: passwordValue.value,
        }).then((res) => {
          $store.commit("loginToken", res.data.token);
          sessionStorage.setItem('user',JSON.stringify(res.data.user))
          console.log(res);
          switch (res.code) {
            case 200:
              message.success("登录成功");
              router.push("/admin");
              break;
          }
        });
      }
    };
    return {
      usernameValue,
      passwordValue,
      loginButton,
    };
  },
});
</script>

<style lang="less">
body {
  background-color: #ebf4ff;
}
#login {
  width: 100%;
  height: 100%;
  display: flex;
  position: fixed;
  justify-content: center;
  align-items: center;
  .loginBox {
    width: 1200px;
    height: 700px;
    background: #fff;
    border-radius: 20px;
    display: flex;
    justify-content: space-between;
    .left {
      img {
        height: 100%;
      }
    }
    .right {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
      .rightBody {
        width: 80%;
        .tit {
          display: flex;
          justify-content: center;
          p {
            font-size: 35px;
            color: #2c7af6;
            font-weight: bold;
            letter-spacing: 3px;
          }
        }
        .label {
          img {
            position: relative;
            top: 40px;
            left: 10px;
            z-index: 999;
          }
          .input {
            height: 50px;
            border-radius: 5px;
            padding-left: 45px;
          }
        }
        .button {
          margin-top: 20px;
          height: 55px;
          border-radius: 5px;
          box-shadow: 0px 4px 20px 1px rgba(44, 122, 246, 0.36);
          background: linear-gradient(180deg, #2c7af6 0%, #5f9dff 100%);
        }
      }
    }
  }
}
</style>